import { Component, OnInit } from '@angular/core';
import { Observable, of } from 'rxjs';
import { ajax } from 'rxjs/ajax';
import { map, catchError } from 'rxjs/operators';





@Component({
  selector: 'app-site-config',
  templateUrl: './site-config.component.html',
  styleUrls: ['./site-config.component.scss']
})
export class SiteConfigComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
    const apiData = ajax('/api/data').pipe(
      map((res: any) => {
        if (!res.response) {
          throw new Error('Value expected!');
        }
        return res.response;
      }),
      catchError(() => of([]))
    );

    apiData.subscribe({
      next(x: any) { console.log('data: ', x); },
      error() { console.log('errors already caught... will not run'); }
    });

  }

}
